package com.neu.daoimpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.neu.dao.UserRoleDao;
import com.neu.entity.TBUserRole;
import com.neu.util.JDBCUtil;

public class UserRoleDaoImpl implements UserRoleDao {
/**
 *   登录
 */
	@Override
	public boolean denglu(TBUserRole tr) throws SQLException {
		System.out.println(tr.getName()+" , "+tr.getPass());
		Connection conn = null;
		try {
			conn=JDBCUtil.getConn();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String sql = "select * from tb_users_role where name=? and pass=?";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, tr.getName());
		ps.setString(2, tr.getPass());
		ResultSet rs = ps.executeQuery();
		while(rs.next()) {
			return true;
		}
		return false;
	}
/**
 *   注册
 */
	@Override
	public boolean zhuce(TBUserRole tr) throws SQLException {
		Connection conn=null;
		try {
		 conn = JDBCUtil.getConn();
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String sql = "insert into tb_users_role value(null,?,?,0)";
		PreparedStatement ps = conn.prepareStatement(sql);
		//ps.setInt(1, tr.getId());
		ps.setString(1, tr.getName());
		ps.setString(2, tr.getPass());
//		ps.setInt(3, tr.getRole());
//		int role =tr.getRole();
		int a = ps.executeUpdate();
		if(a>0) {
			System.out.println("注册成功:");
		}
		return false;
	}
	}


